$(document).ready(function(){
			loadMenu();
		});
		
		var menus = [];
		
		function loadMenu() {
			$.ajax({
			    url:'/menu/loadMenus.do',
	    type:'POST', //GET
	    async:true,
	    data:{
	    },
	    timeout:5000,    //超时时间
	    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
	    success:function(data){
	    	if (data.success) {
	    		var results = data.data;
	    		for (var i=0;i<results.length;i++) {
	    			menus.push(results[i]);
	    		}
	    		loadGoods(menus);
	    	} else {
	    		alert(data.message);
	    	}
	    },
	    error:function(xhr,textStatus){
	        console.log('错误')
	        console.log(xhr)
	        console.log(textStatus)
	    },
	    complete:function(){
	        console.log('结束')
	    }
	});
}

function loadGoods(menus) {
	for (var i=0; i<menus.length;i++) {
		var menu = menus[i];
		$.ajax({
		    url:'/good/listGoods.do',
		    type:'POST',
		    async:false,
		    data:{
		    	menuId : menus[i].id
		    },
		    timeout : 5000,
			dataType : 'json',
			success : function(data) {
				if (data.success) {
					var results = data.data;
					for (var i = 0; i < results.length; i++) {
						document.getElementById("goodName" + results[i].id).innerHTML = results[i].name;
						document.getElementById("goodPrice" + results[i].id).innerHTML = "￥" + results[i].price;
						document.getElementById("goodURL" + results[i].id).innerHTML = "<a href='/good/toDetail.do?goodId="+results[i].id+"'target='_blank'><img src=/images"+results[i].imageUrl+" width='117' height='180'></a>";
					}
				} else {
					alert(data.message);
				}
			},
			error : function(xhr, textStatus) {
				console.log('错误')
				console.log(xhr)
				console.log(textStatus)
			},
			complete : function() {
				console.log('结束')
			}
		});
	}
}